package com.eamois.dao.graph.impl;

import java.sql.SQLException;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.eamois.dao.graph.GraphLineDao;
import com.eamois.dao.impl.BaseDaoImpl;
import com.eamois.domain.graph.GraphLine;
import com.eamois.domain.graph.GraphTemplate;

public class GraphLineDaoImpl extends BaseDaoImpl<GraphLine> implements GraphLineDao{

	@Override
	@SuppressWarnings("unchecked")
	public Collection<GraphLine> findGraphLineByTemplate(
			final GraphTemplate graphTemplate) {
		// TODO Auto-generated method stub

		return (Collection<GraphLine>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(GraphLine.class);
				criteria.add(Restrictions.eq("graphTemplate", graphTemplate));
				return criteria.list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<GraphLine> findPageLines(final GraphTemplate graphTemplate) {
		// TODO Auto-generated method stub
				return (Collection<GraphLine>) this.getHibernateTemplate().execute(new HibernateCallback() {
					@Override
					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						// TODO Auto-generated method stub
						Criteria criteria = arg0.createCriteria(GraphLine.class);
						criteria.add(Restrictions.eq("graphTemplate", graphTemplate));
						criteria.add(Restrictions.eq("canMove", "false"));
						return criteria.list();
					}
				});
	}

}
